package com.yunhai.recipe.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.model.entity.FmsFormulaRuleEntity;
import com.yunhai.model.entity.fms.FmsFormulaRuleVo;
import com.yunhai.model.vo.fms.FmsFormulaRuleQuery;
import com.yunhai.recipe.service.FormulaRuleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/formulaRule")
public class FormulaRuleController {

	@Resource
	private FormulaRuleService formulaRuleService;


	/**
	 * 获取 FormulaRule 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getFormulaRulePagination(PaginationVo paginationVo, FmsFormulaRuleQuery fmsFormulaRuleQuery ) throws Exception {
		IPage page = formulaRuleService.getFormulaRulePagination(paginationVo, fmsFormulaRuleQuery );
		return Ret.toPage(page);
	}


	/**
	 * 获取 FormulaRule 所有数据
	 */
	@GetMapping("/allList")
	public Ret getFormulaRuleAllList( FmsFormulaRuleQuery fmsFormulaRuleQuery ) throws Exception {
		List<FmsFormulaRuleEntity> list = formulaRuleService.getFormulaRuleAllList( fmsFormulaRuleQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 FormulaRule 详情
	 */
	@GetMapping("/{id}")
	public Ret getFormulaRuleDetailById(@PathVariable Long id) throws Exception {

	    FmsFormulaRuleEntity fmsFormulaRuleEntity = formulaRuleService.getFormulaRuleDetail(id);
		return Ret.ok(fmsFormulaRuleEntity);
	}


	/**
	 * 新增 FormulaRule
	 * */
	@PostMapping("")
	public Ret addFormulaRule(@RequestBody FmsFormulaRuleVo fmsFormulaRuleVo) throws Exception {

		formulaRuleService.addFormulaRule(fmsFormulaRuleVo);
		return Ret.ok();
	}


	/**
	 * 更新 FormulaRule
	 * */
	@PutMapping("")
	public Ret updateFormulaRule(@RequestBody FmsFormulaRuleVo fmsFormulaRuleVo) throws Exception {

		formulaRuleService.updateFormulaRule(fmsFormulaRuleVo);
		return Ret.ok();
	}


	/**
	 * 删除 FormulaRule
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveFormulaRule( @RequestBody List<Long> ids ) throws Exception {

	    formulaRuleService.batchRemoveFormulaRule(ids);
		return Ret.ok();
	}
}
